﻿Imports System.Net.Mail

Partial Class request_admin
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim acs As String = acsBox.Text
        Dim uni_id As Integer = Integer.Parse(UniDropDownList.SelectedValue.ToString)
        Dim name As String = nameBox.Text
        Dim email As String = emailBox.Text
        Dim phone As String = phoneBox.Text
        Dim position As String = posBox.Text

        Dim insert As Boolean = ACSService.sendAdminRequest(acs, name, email, phone, uni_id, position)

        If insert Then
            Dim str As New StringBuilder()
            str.AppendLine("<h1>New Admin Login Request</h1>")
            str.AppendLine("<p>Hello there, you have a new admin login request</p>")
            str.AppendLine("<p>ACS Name : " + acs + "</p>")
            str.AppendLine("<p>University : " + UniDropDownList.SelectedItem.ToString + "</p>")
            str.AppendLine("<p>Contact Name : " + name + "</p>")
            str.AppendLine("<p>Contact Email : " + email + "</p>")
            str.AppendLine("<p>Contact Number : " + phone + "</p>")
            str.AppendLine("<p>Position : " + position + "</p>")
            str.AppendLine("<p><a>Click here</a> to process this request</p>")

            Dim body As String = str.ToString()

            Dim message As New MailMessage(New MailAddress("no-reply@acs-membership.com", "ACS New Admin Request"), New MailAddress("jakinnagbe@gmail.com"))

            message.Subject = "Welcome to ACS"
            message.Body = body
            message.BodyEncoding = Encoding.ASCII
            message.IsBodyHtml = True

            Dim smtp As New SmtpClient()
            smtp.Send(message)

            Response.Redirect("success.aspx")
        Else
            msgLabel.Text = "Invalid request! please try again."
        End If

    End Sub
End Class
